import socket
import netifaces
import requests
import json
from time import sleep

while True:
    ips = []
    for interface in netifaces.interfaces():
        addrs = netifaces.ifaddresses(interface)
        if netifaces.AF_INET in addrs:
            for addr in addrs[netifaces.AF_INET]:
                ips.append(addr['addr'])

    url = "http://10.10.18.50:6333/register"

    data = json.dumps(ips)

    try:
        # 发送POST请求并获取响应
        response = requests.post(url, data=data, timeout=3)
        # 打印响应状态码
        print(f"响应状态码: {response.status_code}")
        # 打印响应内容
        print(response.text)
    except requests.exceptions.RequestException as e:
        print(f"发送POST请求时出错: {e}")
    print(ips)

    sleep(5)
